﻿using System.Collections.Generic;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using Contracts.Entities;

namespace Model.MovieElements
{
    class StudioConverter
    {
        /// <summary>
        /// Für das Lesen einer MovieStudios-Relation
        /// </summary>
        public static IEnumerable<MovieElement> GetElements(EntityCollection<Studios> studios)
        {
            var results = new List<MovieElement>();
            foreach (var entity in studios)
                results.Add(GetElement(entity));

            return results;
        }

        /// <summary>
        /// Für das Lesen aller Studios aus Datenbank
        /// </summary>
        public static IEnumerable<MovieElement> GetElements(ObjectSet<Studios> studios)
        {
            var results = new List<MovieElement>();
            foreach (var entity in studios)
                results.Add(GetElement(entity));

            return results;
        }

        /// <summary>
        /// Für das Schreiben der Studios aus Tmdb-Quelle
        /// </summary>
        public static IEnumerable<MovieElement> GetElements(IEnumerable<TmdbMovieStudio> studios)
        {
            var items = new List<MovieElement>();

            foreach (var item in studios)
            {
                items.Add(new MovieElement()
                {
                    Name = item.Name,
                    Type = MovieElementType.Studio
                });
            }

            return items;
        }

        /// <summary>
        /// Für das Schreiben der Studios aus eigener Quelle
        /// </summary>
        public static EntityCollection<Studios> GetEntities(IEnumerable<MovieElement> actors)
        {
            var results = new EntityCollection<Studios>();

            foreach (var item in actors)
                results.Add(GetEntity(item));

            return results;
        }

        public static MovieElement GetElement(Studios studio)
        {
            return new MovieElement()
            {
                Id = studio.Id,
                Name = studio.Name,
                Type = MovieElementType.Studio
            };
        }

        public static Studios GetEntity(MovieElement studio)
        {
            return new Studios()
            {
                Id = studio.Id,
                Name = studio.Name
            };
        }
    }
}
